<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport"
          content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"/>
    <meta name="msapplication-tap-highlight" content="no"/>
    <title>index</title>
    <!--=S assets=-->
    <link rel="stylesheet" type="text/css" href="css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="css/main.css"/>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/k/seed-min.js"></script>
    <script type="text/javascript" src="js/global.js"></script>
    <!--=E assets=-->
</head>
<body>
<div id="page">
    <div id="content">
        <div class="layout index-wrap">
            <!--=S header =-->
            <div id="header">
                <a href="#" id="J_sideBarBtn" class="bar-btn menu-btn fl has-new">
                    <b class="new-icon"></b>
                </a>
                <a href="at-list.html" id="J_attetion" class="bar-btn attention-btn rl">
                </a>
                    <span class="title">
                        Pa一下
                    </span>
            </div>
            <!--=E header =-->

            <!--=S index-mod=-->
            <link rel="stylesheet" type="text/css" href="css/index-mod.css"/>
            <div class="index-mod">
                <div class="index-bd">
                    <div class="avt-list" id="J_avtList">
                    </div>
                </div>
                <div class="index-ft">
                    <a href="#" id="J_avtListRefresh" class="avt-list-refresh">
                        <b class="icon-refresh"></b>换一组试试
                    </a>
                </div>
            </div>
            <!--=E index-mod=-->

            <!--=S footer =-->
            <link rel="stylesheet" type="text/css" href="css/footer.css"/>
            <div id="footer">
                <dl class="f-left">
                    <dt class="j_cardWatch" data-uid="2">
                        <img src="img/empty.jpg" alt=""/>
                        <b class="new-icon"></b>
                    </dt>
                    <dd class="pa-1">
                        <p></p>
                        19:33
                    </dd>
                </dl>
                <dl class="f-right">
                    <dt>
                        <img src="img/3.jpg" alt=""/>
                    </dt>
                    <dd class="pa-1">
                        <p></p>
                        17:33
                    </dd>
                </dl>
            </div>
            <!--=E footer =-->

        </div>
    </div>
</div>
<script>
    document.addEventListener('deviceready', function () {

        KISSY.use('com/login', function (S, Login) {
            Login.check(indexInit);
        });

        function indexInit() {
            KISSY.use('dom,event,com/util', function (S, DOM, Event, Util) {
                var avtList = DOM.get("#J_avtList"),
                        btn = DOM.get("#J_avtListRefresh");
                var url = Util.url('users'),
                        TEMPLETE = '<a href="#{uid}" data-uid="{uid}" class="avt-item"><img src="{pic}" alt="{nickname}"/></a>';

                var LOADDING='refresh-loadding';

                Event.on(btn, 'tap', function (ev) {
                    ev.halt();
                    //不重复刷新
                    if(DOM.hasClass(btn,LOADDING))return;
                    DOM.addClass(btn, LOADDING);
                    Util.get(url, null, {}, function (d) {
                        if (d.isSuccess == 1) {
                            var arr=[];
                            S.each(d.data,function(item){
                                arr.push(S.substitute(TEMPLETE,item));
                            });
                            DOM.html(avtList,arr.join(""));
                        }
                    }, function () {
                        DOM.removeClass(btn, LOADDING);
                    });
                });

                Event.fire(btn,'tap');

                //发消息
                KISSY.use('dom,event,com/sendMessage', function (S, DOM, Event, SendMessage) {
                    Event.delegate(avtList, 'tap','a',function (ev) {
                        ev.halt();
                        var target=ev.currentTarget;
                        SendMessage.show(target);
                    });
                });
            });


            //看名片
            KISSY.use('dom,event,com/card', function (S, DOM, Event, Card) {
                Event.on(DOM.query(".j_cardWatch"), 'tap', function (ev) {
                    ev.halt();
                    var target=ev.currentTarget;
                    Card.show(target);
                });
            });

            //侧滑菜单
            KISSY.use('dom,event,com/menu', function (S, DOM, Event, Menu) {
                Event.on(DOM.get("#J_sideBarBtn"), 'tap', function (ev) {
                    ev.halt();
                    Menu.toggle();
                });
                Menu.setCur('.m1');
            });
        }

    }, false);
</script>
</body>
</html>
